package com.juc.threadPoolExecutor.threadPoolExecutor1;

import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class Run2_1 {
	//线程池添加的线程数量<=corePoolSixe
    //队列使用LinkedBlockingDeque类
	//并且线程数量<=corePoolSize
	//所以keepAliveTime >5 时也不清除空闲线程
	public static void main(String[] args) throws InterruptedException {
		Runnable runnable =new Runnable() {
			
			@Override
			public void run() {
				try {
					System.out.println(Thread.currentThread().getName() + " run! " +System.currentTimeMillis());
					Thread.sleep(1000);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		};
		ThreadPoolExecutor executor = new ThreadPoolExecutor(7, 8, 5, TimeUnit.SECONDS, new LinkedBlockingDeque<Runnable>());
		executor.execute(runnable);//1
		executor.execute(runnable);//2
		executor.execute(runnable);//3
		executor.execute(runnable);//4
		executor.execute(runnable);//5
		executor.execute(runnable);//6
		executor.execute(runnable);//7
		/*executor.execute(runnable);//8
		executor.execute(runnable);//9
*/		Thread.sleep(300);
        //车中可载人的标准人数
		System.out.println("A: " + executor.getCorePoolSize());
		//车中可载人的最大数
		System.out.println("A: " + executor.getMaximumPoolSize());
		//车中正在载的人数
		System.out.println("A: " + executor.getPoolSize());
		//扩展车中正在载的人数
		System.out.println("A: " + executor.getQueue().size());
		Thread.sleep(10000);
		System.out.println("B: " + executor.getCorePoolSize());
		System.out.println("B: " + executor.getMaximumPoolSize());
		System.out.println("B: " + executor.getPoolSize());
		System.out.println("B: " + executor.getQueue().size());
	}
}
